<?php
require_once ('libraryfiles/config.php');
$content = 'user.php';
$site_title = 'User';
require_once TMP_USER_PATH;
$success = isset($_GET ['success']) ? $_GET ['success'] : '';
if (isset($_GET ['success']) != "") {
    $message = $_GET ['success'];
} else {
    $message = '';
}
$user_id = isset($_GET['id']) ? $_GET['id'] : '';
if (empty($user_id)) {
    ?>
    <script type="text/javascript">
        window.location = "<?php echo W_ROOT; ?>"
    </script>
    <?php
    exit();
} else {
    $result = select(Tbluser::Tbluser, '', array(Tbluser::id => $user_id));
    $row_user = mysql_fetch_assoc($result);
    if (!empty($row_user)) {
        $f_name = $row_user[Tbluser::first_name];
        $l_name = $row_user[Tbluser::last_name];
        $create_date = $row_user[Tbluser::cdate];
        $email = $row_user[Tbluser::email];
        $tel = $row_user[Tbluser::phone];
        $local = $row_user[Tbluser::address];
    }
// if we got an error then we display it here
    if ($message) {
        ?>
        <div class="alert alert-success fade in">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <h3 class="alert-heading">
                <!--Well done! You successfully.-->
                <?php echo $lang['SUCCESSSMS']; ?>
            </h3>
            <p style="font-size: 16px;">
            <blink>
                <?php echo @$lang[$message]; ?>
            </blink>
        </p>
        </div>
        <?php
    }
    ?>
    <!--End Message-->
    <!--Messsage-->
    <?php if (!empty($_GET['message'])) { ?>
        <div class="row-fluid">
            <div class="span12">
                <?php
                if (isset($_GET ['message']) != "") {
                    $message = $_GET ['message'];
                } else {
                    $message = '';
                }
                // if we got an error then we display it here
                if ($message) {
                    ?>
                    <div class="alert alert-block fade in">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <h3 class="alert-heading">
                            <!--Heads up! This alert needs your attention-->
                            <?php echo $lang['HEADE_UP_ALERT']; ?>
                        </h3>
                        <p style="font-size: 16px;">
                        <blink>
                            <?php echo @$lang[$message]; ?>
                        </blink>
                        </p>
                    </div>
                    <?php
                }
                ?>
            </div>
        </div>
        <!--End Message-->
        <!--Error-->
        <?php
    }
    $CURRENT_URL = W_ROOT;
    if (isset($_GET ['error']) != "") {
        $error = isset($_GET ['error']) ? $_GET ['error'] : '';
        switch ($error) {
            case 1 :
                $message = $lang ['EMAILADDINVALID'];
                break;
            case 2 :
                $message = 'Email Address &amp; Password is Invalid';
                break;
            case 3 :
                $message = $lang ['PLSSELECTTHEACCOUNT'];
                break;
            case 4 :
                $message = "Missing provider application credentials.";
                break;
            case 5 :
                $message = "Authentification failed. The user has canceled the authentication or the provider refused the connection.";
                break;

            default :
                $message = "Unspecified error!";
        }
    } else {
        $message = '';
    }
    ?>

    <!--end Error-->

    <!--test foundation formlogin-->
    <?php if (!empty($_GET['error'])) { ?>
        <div class="row-fluid">
            <div class="span12">
                <?php
                $CURRENT_URL = W_ROOT;
                if (isset($_GET ['error'])) {
                    $message = $_GET ['error'];
                    ?>
                    <div class="alert alert-block alert-error fade in">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <h3 class="alert-heading">
                            <!--Oh snap! You got an error!-->
                            <?php echo $lang['SNAB_ERROO']; ?>
                        </h3>
                        <p style="font-size: 16px;">
                        <blink>
                            <?php echo @$lang[$message]; ?>
                        </blink>
                        </p>
                    </div>
                    <?php
                }
                ?>
            </div>
        </div>
    <?php } ?>
    <div class="row-fluid">
        <div class="span9 category">
            <div id="content">
                <div class="title">
                    <h1 class="category-title">User information</h1>
                </div>

                <div class="category-info">
                    <div class="row-fluid">
                        <div class="span6">
                            <h5>Information:</h5>
                            <table class="table table-bordered">
                                <tr>
                                    <td style="width: 30%"><b>First Name:</b></td>
                                    <td><?php echo @$f_name; ?></td>
                                </tr>
                                <tr>
                                    <td><b>Last Name:</b></td>
                                    <td><?php echo @$l_name; ?></td>
                                </tr>
                                <tr>
                                    <td><b>Member Since:</b></td>
                                    <td><?php echo date('d-m-Y', @$create_date); ?></td>
                                </tr>
                            </table>
                        </div>
                        <div class="span6">
                            <h5>Contact:</h5>
                            <table class="table table-bordered">
                                <tr>
                                    <td style="width: 20%"><b>Tel:</b></td>
                                    <td><?php echo @$tel; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 20%"><b>Email:</b></td>
                                    <td><?php echo @$email; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 20%"><b>Location:</b></td>
                                    <td><?php echo @$local; ?></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>


                <div class="product-filter">
                    <div class="display"><b>Last Products:</b></div>
                    <div class="product-compare"><a href="<?php echo base_url ?>product/?user=<?php echo $user_id; ?>" id="compare-total">View all</a></div>
                </div>


                <!--product list-->
                <?php
                $rowsPerPage = isset($_GET['num']) ? $_GET['num'] : '12';
                $sql = "SELECT t1.*, t1.top_view, t3.price, t3.pid, t2.images, t2.thumbnail FROM tblproduct AS t1
                        LEFT JOIN tblimage AS t2 ON t1.id=t2.product_id
                        INNER JOIN tblproduct_in_pharmacy AS t3 ON t1.id=t3.product_id
                        WHERE  t1.status = 1 AND t1.owner = '" . $user_id . "' GROUP BY t1.id ORDER BY t1.id DESC";
                $result = mysql_query(getPagingQuery($sql, $rowsPerPage));
                ?>


                <div class="product-grid"> 
                    <?php
                    $i = 1;
                    $border = "";
                    if (dbNumRows($result) > 0) {
                        while ($data = mysql_fetch_assoc($result)) {
                            /* get price */
                            $price = mysql_query("SELECT price,regular_price FROM tblproduct_in_pharmacy WHERE product_id=" . $data['id'] . " ORDER BY price ASC LIMIT 0,1");
                            $myprice = mysql_fetch_assoc($price);
                            $price1 = mysql_query("SELECT price,regular_price FROM tblproduct_in_pharmacy WHERE product_id=" . $data['id'] . " ORDER BY price DESC LIMIT 0,1");
                            $myprice1 = mysql_fetch_assoc($price1);
                            /* end get price */
                            if ($i % 4 == 1) {
                                echo '<div class="row-fluid box-product">';
                            }
                            ?>
                            <div class="span3 product_block ">
                                <?php echo showProduct($data, $myprice);?>
                            </div>
                            <?php
                            if ($i % 4 == 0) {
                                echo "</div>";
                            }
                            $i++;
                        }
                        if ($i % 4 != 1)
                            echo "</div>";
                    }
                    ?>
                    <div class="clear-both"></div>
                    <div style="float: right;"><a class="secondary button" href="<?php echo base_url ?>product/?user=<?php echo $user_id; ?>">View All Products</a></div>
                </div>
                <!--end product list-->
            </div>
        </div>




        <div class="span3">
            <div id="column-right" class="sidebar">
                <?php include(S_ROOT . '/templates/sidebar-home.php'); ?>
            </div>
        </div>
    </div>
    <?php
}?>